package com.chenglu.android.mine.beans;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chenglu.android.R;
import com.chenglu.android.bean.SmsCodeBean;
import com.chenglu.android.common.base.BaseActionBarActivity;
import com.chenglu.android.common.net.Constant;
import com.chenglu.android.common.utils.ToastUtils;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.mine.bean.AmountTypeBean;
import com.chenglu.android.mine.bean.BeansDetailBean;
import com.chenglu.android.mine.bean.UserInfoBean;
import com.chenglu.android.mine.beans.mvp.contract.BeansContract;
import com.chenglu.android.mine.beans.mvp.presenter.BeansPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author: lyj
 * @Created: by Copyright 2023 6 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：
 */
public class BeansActivity extends BaseActionBarActivity<BeansPresenter> implements BeansContract.View {
    @BindView(R.id.tv_beans)
    TextView tvBeansValues;
    @BindView(R.id.tv_active)
    TextView tvActive;
    @BindView(R.id.tv_total_bean)
    TextView tvTotalBean;
    @BindView(R.id.tv_bean_record)
    TextView tvBeanRecord;
    @BindView(R.id.tv_account_beans)
    TextView tvAccountBeans;
    @BindView(R.id.tv_active_beans)
    TextView tvActiveBeans;
    @BindView(R.id.tv_tip)
    TextView tvTip;
    @BindView(R.id.ll_loading_data)
    LinearLayout llLoadingData;
    @BindView(R.id.tv_no_data)
    TextView tvNoData;
    @BindView(R.id.ll_loading_no_data)
    LinearLayout llLoadingNoData;

    private String token;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_beans;
    }

    @Override
    protected void initView() {
        setCenterText("我的红豆");
        mPresenter = new BeansPresenter();
        mPresenter.attachView(this);
        token = getToken();

//        mPresenter.getUserInfo(token);
        mPresenter.getBeansDetails(token);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.tv_active, R.id.tv_bean_record})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_active:
                mPresenter.getActiveBeans(token);
                break;
            case R.id.tv_bean_record:
                startActivity(new Intent(this, BeansRecordActivity.class)
                .putExtra(BeansRecordActivity.AMOUNTTYPE,3));
                break;
        }
    }


    @Override
    public void getActiveBeans(SmsCodeBean bean) {
        if (bean.getCode().equals(Constant.HTTPCODE200)) {
            ToastUtils.show(bean.getMsg());
        } else {
            ToastUtils.show(bean.getMsg());
        }
    }

    @Override
    public void getAmountTypeList(AmountTypeBean bean) {

    }


    @Override
    public void getUserInfo(UserInfoBean bean) {

    }

    @Override
    public void getBeansDetails(BeansDetailBean bean) {
        if (bean.getCode().equals(Constant.HTTPCODE200)) {
            llLoadingData.setVisibility(View.VISIBLE);
            llLoadingNoData.setVisibility(View.GONE);

            tvBeansValues.setText(Utils.formatZeroNumber(bean.getData().getBeans()));//红豆值
            tvTotalBean.setText(Utils.formatZeroNumber(bean.getData().getTotalBeans())); //总共获取的红豆
            tvAccountBeans.setText(Utils.formatZeroNumber(bean.getData().getWaitBeans()));//待入账红豆
            tvActiveBeans.setText(Utils.formatZeroNumber(bean.getData().getActiveBeans()));//已激活红豆
            tvTip.setText(Html.fromHtml(bean.getData().getTips()));
        }else {
            llLoadingData.setVisibility(View.GONE);
            llLoadingNoData.setVisibility(View.VISIBLE);
        }
    }


    @Override
    public void onError(String errorMsg) {
        super.onError(errorMsg);
    }
}
